import unittest
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By

class jiuxian(unittest.TestCase):
    def setUp(self) -> None:
        self.driver = webdriver.Edge()
        self.driver.maximize_window()
        self.driver.get('https://www.jiuxian.com/')
        sleep(5)


    def tearDown(self) -> None:
        sleep(20)
        self.driver.quit()


    def test_jiuxian_01(self):
        # 1.点击请登录
        self.driver.find_element(By.LINK_TEXT,'请登录').click()
        sleep(5)
        #2.输入账号
        self.driver.find_element(By.ID,'userName').send_keys('17733058407')
        sleep(2)

        #3.输入密码
        self.driver.find_element(By.XPATH,'//*[@id="password"]').send_keys('Li10140910')
        sleep(20)

        #4.点击登录
        self.driver.find_element(By.NAME,'bi_Usuallogin').click()
        sleep(2)
        # 6 点击 确定
        self.driver.find_element(By.XPATH,'//a[@id="bindSub"]').click()
        sleep(2)

        # 7 定位国台
        self.driver.find_element(By.PARTIAL_LINK_TEXT,'国台').click()
        sleep(2)

        # 8 切换窗口
        self.driver.switch_to.window(self.driver.window_handles[-1])
        sleep(2)

        # 9 进入店铺
        self.driver.find_element(By.XPATH,'/html/body/div[6]/div/div[2]/div[2]/a').click()
        sleep(2)

        # 切换窗口
        self.driver.switch_to.window(self.driver.window_handles[-1])
        sleep(2)

        #向下滚动
        self.driver.execute_script('window.scrollTo(0,2000)')
        sleep(5)

        # 10 点击加入购物车
        self.driver.find_element(By.XPATH,'//*[@id="layoutContain"]/div/div/div/div/div/map[1]/area').click()
        sleep(5)

        # 切换窗口
        self.driver.switch_to.window(self.driver.window_handles[-1])
        sleep(2)

        # 11 点击到货通知
        self.driver.find_element(By.PARTIAL_LINK_TEXT,'到货通知').click()
        sleep(2)

        # # 12 填写邮箱地址
        # self.driver.find_element(By.XPATH,'//*[@id="itemCon"]/div[1]/input').send_keys('17733058407@163.com')
        # sleep(2)

        # 13 点击确认
        self.driver.find_element(By.XPATH,'//*[@id="notify-sure"]').click()
        sleep(2)

        # 14 点击确认
        self.driver.find_element(By.XPATH,'//*[@id="notify-popSuc-sure"]').click()
        sleep(2)

    def test_jiuxian_02(self):
        # 1 点击五粮液
        self.driver.find_element(By.LINK_TEXT,'五粮液').click()
        sleep(2)

        # 切换窗口
        self.driver.switch_to.window(self.driver.window_handles[-1])
        sleep(2)

        # 2 选择商品
        self.driver.find_element(By.XPATH,'//img[@src="https://img10.jiuxian.com/2021/0817/7a376cfc1a4d40829d39f792c502e8d94.jpg"]').click()
        sleep(2)

        # 切换窗口
        self.driver.switch_to.window(self.driver.window_handles[-1])
        sleep(2)

        #断言
        dy1=self.driver.find_element(By.XPATH,'/html/body/div[5]/div[2]/div[2]/div[1]/h1').text
        print(dy1)


#执行
if __name__ == '__main__':
    unittest.main()